import '@tarojs/async-await'
import Taro, { Component, getCurrentPages } from '@tarojs/taro'
import { Provider } from '@tarojs/redux'

import Index from './pages/personal/index'
const interactiveVideo = require('@/faceid-interactive-video-mpsdk/main')
const options = {
  livenessMode: 1,
  isHideGuide: false
}
interactiveVideo.init(options)

import { getPersonalInfo } from '@/api/index'
import { resetData } from '@/actions/user'
import configStore from './store'

import './app.scss'
import './custom-variables.scss'
import './assets/fonts/iconfont.css'

// 如果需要在 h5 环境中开启 React Devtools
// 取消以下注释：
// if (process.env.NODE_ENV !== 'production' && process.env.TARO_ENV === 'h5')  {
//   require('nerv-devtools')
// }
const store = configStore()

class App extends Component {

  config = {
    pages: [
      'pages/taskSquare/index',
      'pages/personal/index',
      'pages/taskList/index',
      'pages/taskDetail/index',
      'pages/contractList/index',
      'pages/resume/index',
      'pages/lessonRecord/index',
      'pages/face/index',
      'pages/certificate/index',
      'pages/certificateUpload/index',
      'pages/sign/index',
      'pages/login/index',
      'pages/home/index',
      'pages/user/index',
      'pages/cheques/index',
      'pages/web/index',
      'pages/preview/index',
      "faceid-interactive-video-mpsdk/index/index",
      "faceid-interactive-video-mpsdk/room/room",
      'pages/employComputed/index'
    ],
    window: {
      backgroundTextStyle: 'light',
      navigationBarBackgroundColor: '#fff',
      navigationBarTitleText: 'WeChat',
      navigationBarTextStyle: 'black',
      onReachBottomDistance:50
    },
    tabBar: {
      color: '#000',
      selectedColor: '#22ADF7',
      backgroundColor: '#fff',
      borderStyle: 'white',
      list: [
        { pagePath: 'pages/taskSquare/index', text: '任务广场', iconPath: 'assets/img/icon_home.png', selectedIconPath: 'assets/img/icon_home_active.png' },
        { pagePath: 'pages/taskList/index', text: '我的任务', iconPath: 'assets/img/icon_task.png', selectedIconPath: 'assets/img/icon_task_active.png' },
        { pagePath: 'pages/personal/index', text: '个人中心', iconPath: 'assets/img/icon_person.png', selectedIconPath: 'assets/img/icon_person_active.png' },
      ]
    },
    permission: {
    　　"scope.userLocation": {
    　　　　"desc":"你的位置信息将用于小程序位置接口的效果展示"
    　　}
    }
  }

  constructor(props) {
    super(props)
    // const sign = Taro.getStorageSync("isSign")
    // if (sign) {
    //   this.getPersonalInfo()
    // } else {
    //   Taro.reLaunch({url: '/pages/home/index'})
    // }
  }

  getPersonalInfo = () => {
    const mobile = JSON.parse(Taro.getStorageSync("info")).mobile
    getPersonalInfo({loginAccount: mobile}).then(({code}) => {
      if (code === 2020) {
        console.log(store.dispatch(resetData()))
        Taro.reLaunch({url: '/pages/home/index'})
      }
    }).catch(e => [
      console.log(e)
    ])
  }

  componentDidMount () {}

  componentDidShow () {}

  componentDidHide () {}

  componentDidCatchError () {}

  // 在 App 类中的 render() 函数没有实际作用
  // 请勿修改此函数
  render () {
    return (
      <Provider store={store}>
        <Index />
      </Provider>
    )
  }
}

Taro.render(<App />, document.getElementById('app'))
